import { useEffect, useState } from "react";

const useMouse = () => {
  // 鼠标事件
  const getMouseIndex = (event: MouseEvent) => {
    setX(event.clientX);
    setY(event.clientY);
  };
  const [x, setX] = useState(0);
  const [y, setY] = useState(0);
  useEffect(() => {
    window.addEventListener("mousemove", getMouseIndex);
    return () => {
      window.removeEventListener("mousemove", getMouseIndex);
    };
  }, []);
  return [x, y];
};
export default useMouse;
